var baseUrl = require('../../utils/urllink.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showTopTips: false,
    showTopTipsText: '',
    nickname:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    //请求服务器
    wx.request({
      url: baseUrl +'weapp/Users/info.html',
      data: {
        user_id: app.globalData.user_id,
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      }, // 设置请求的 header
      success: function (res) {
        console.log(res.data)
        that.setData({
          userInfo: res.data,
          nickname: res.data.nickname,
        })
      },
      fail: function () {
      },
      complete: function () {
        // complete
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  formSubmit:function(e){
    var that = this;
    var nickname = e.detail.value.nickname;
    if (nickname <= 0) {
      this.setData({
        showTopTipsText: '请输入昵称',
        showTopTips: true
      })
      setTimeout(function () {
        that.setData({
          showTopTips: false
        });
      }, 3000);
    }else{
      //请求服务器
      wx.request({
        url: baseUrl +'weapp/Users/modi_users.html',
        data: {
          user_id: app.globalData.user_id,
          nickname: nickname,

        },
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        header: {
          'content-type': 'application/json'
        }, // 设置请求的 header
        success: function (res) {
          console.log(res.data)
          if (res.data.code == 0) {
            wx.switchTab({
              url: '../mine/mine',
            })
          } else {
            console.log("修改错误")
          }
        },
        fail: function () {
        },
        complete: function () {
        }
      })
    }


  },



})